package com.vstudy.zx.dao;

import com.vstudy.zx.dao.provider.ArticleManageDaoProvider;
import com.vstudy.zx.entity.Article;
import com.vstudy.zx.utils.page.ArticlePage;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.StatementType;

import java.util.List;

public interface ArticleManageDao {
    @SelectProvider(type = ArticleManageDaoProvider.class, method = "count")
    Long count(ArticlePage page);

    //  文章管理分页，存储过程，返回page.totalCouont
    @Select("call sp_article_page(#{page.pageIndex}, #{page.pageSize},#{te_id},#{grade_id},#{subject_id}," +
            "#{page.title}, #{page.totalCount, mode=OUT,jdbcType=BIGINT});")
    @Options(statementType = StatementType.CALLABLE)
    @Results({
            @Result(column = "outline_id", property = "outline",
                    one = @One(select = "com.vstudy.zx.dao.OutlineDao.selectById")),
            @Result(column = "article_author", property = "author",
                    one = @One(select = "com.vstudy.zx.dao.TeacherDao.selectById"))
    })
    List<Article> selectPage(@Param("page") ArticlePage page, @Param("te_id") Long te_id,
                             @Param("grade_id") Integer grade_id, @Param("subject_id") Long subject_id);

    @Select("select * from tb_article where outline_id=#{oid} limit #{page.skip}, #{page.pageSize} ")
    @Options(statementType = StatementType.CALLABLE)
    @Results({
            @Result(column = "outline_id", property = "outline",
                    one = @One(select = "com.vstudy.zx.dao.OutlineDao.selectById")),
            @Result(column = "article_author", property = "author",
                    one = @One(select = "com.vstudy.zx.dao.TeacherDao.selectById"))
    })
    List<Article> selectPageByOid(@Param("page") ArticlePage page, @Param("oid") Long oid);
}
